package com.docker.fy.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.docker.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.docker.common.annotation.Log;
import com.docker.common.core.controller.BaseController;
import com.docker.common.core.domain.AjaxResult;
import com.docker.common.enums.BusinessType;
import com.docker.fy.domain.DoctorRegistration;
import com.docker.fy.service.IDoctorRegistrationService;
import com.docker.common.utils.poi.ExcelUtil;
import com.docker.common.core.page.TableDataInfo;

/**
 * 工作台接诊Controller
 * 
 * @author ruoyi
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/work/work")
public class DoctorRegistrationController extends BaseController
{
    @Autowired
    private IDoctorRegistrationService doctorRegistrationService;

    //获取全部患者信息
    @Anonymous
    @GetMapping("/patient/list")
    public AjaxResult getPatientList() {
        return AjaxResult.success(doctorRegistrationService.getAllPatientList());
    }


    /*
    * 保存诊断信息
    * */
    @Anonymous
    @PostMapping("/savePrescription")
    public AjaxResult savePrescription(@RequestBody Map map) {
//        System.out.println(map);
        //药品信息
//        List<Map> medicineList = (List<Map>) map.get("MySelectedMedicinesIdAndQuantity");
//        medicineList.forEach(medicine -> {
//            System.out.println(medicine);
//        });
//        System.out.println("---------------------");
//        //检查项目信息
//        List<Map> checkList = (List<Map>) map.get("MySelectedExaminationsId");
//        checkList.forEach(check -> {
//            System.out.println(check);
//        });
//        System.out.println("---------------------");
//        //附加费用信息
//        List<Map> extraList = (List<Map>) map.get("MySelectedAdditionalFeesId");
//        extraList.forEach(extra -> {
//            System.out.println(extra);
//        });
//        System.out.println("---------------");
//        //患者信息
//        Map patientInfo = (Map) map.get("MyPatient");
//        System.out.println(patientInfo);
//        System.out.println("---------------");
//        //医生信息
//        Map doctorInfo = (Map) map.get("MyUser");
//        System.out.println(doctorInfo);
//        //部门信息
//        Map departmentInfo = (Map) map.get("MyDept");
//        System.out.println(departmentInfo);
//        System.out.println("---------------");
//        //病历信息
//        Map medicalRecordInfo = (Map) map.get("MyMedicalForm");
//        System.out.println(medicalRecordInfo);
//        System.out.println("---------------");
//        //处方信息
//        Map prescriptionInfo = (Map) map.get("MyPrescriptionForm");
//        System.out.println(prescriptionInfo);
//        System.out.println("---------------");

        AjaxResult ajaxResult = doctorRegistrationService.savePrescription(map);
        return ajaxResult;
    }

    /**
     * 查询工作台接诊列表
     */
    @PreAuthorize("@ss.hasPermi('work:work:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorRegistration doctorRegistration)
    {
        startPage();
        List<DoctorRegistration> list = doctorRegistrationService.selectDoctorRegistrationList(doctorRegistration);
        return getDataTable(list);
    }

    /**
     * 导出工作台接诊列表
     */
    @PreAuthorize("@ss.hasPermi('work:work:export')")
    @Log(title = "工作台接诊", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorRegistration doctorRegistration)
    {
        List<DoctorRegistration> list = doctorRegistrationService.selectDoctorRegistrationList(doctorRegistration);
        ExcelUtil<DoctorRegistration> util = new ExcelUtil<DoctorRegistration>(DoctorRegistration.class);
        util.exportExcel(response, list, "工作台接诊数据");
    }

    /**
     * 获取工作台接诊详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:work:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(doctorRegistrationService.selectDoctorRegistrationById(id));
    }

    /**
     * 新增工作台接诊
     */
    @PreAuthorize("@ss.hasPermi('work:work:add')")
    @Log(title = "工作台接诊", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorRegistration doctorRegistration)
    {
        return toAjax(doctorRegistrationService.insertDoctorRegistration(doctorRegistration));
    }

    /**
     * 修改工作台接诊
     */
    @PreAuthorize("@ss.hasPermi('work:work:edit')")
    @Log(title = "工作台接诊", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorRegistration doctorRegistration)
    {
        return toAjax(doctorRegistrationService.updateDoctorRegistration(doctorRegistration));
    }

    /**
     * 删除工作台接诊
     */
    @PreAuthorize("@ss.hasPermi('work:work:remove')")
    @Log(title = "工作台接诊", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(doctorRegistrationService.deleteDoctorRegistrationByIds(ids));
    }
}
